var commonUtil = require("../../../utils/commonUtil.js")
var globalData = getApp().globalData;
var httpsUrl = globalData.httpsUrl;
var imgUrl = globalData.imgUrl;
Page({

  data: {
    imgUrl: imgUrl,
    titleFlag:0,
    list:[],
    total:0,
  },
  list: function () {
    var that = this;
    var params = new Object();
    params.status = this.data.titleFlag;
    params.pageNo = 0;
    let openId = wx.getStorageSync("openidKey");
    wx.showLoading({ title: '请稍等...', })
    wx.request({
      header: { "openId": openId, "content-Type": "application/x-www-form-urlencoded" },
      url: httpsUrl + "/car/list/" + that.data.titleFlag,
      dataType: "json",
      method: "GET",
      data: params,
      success: function (res) {
        wx.hideLoading();
        res = res.data;
        console.log("car：" + JSON.stringify(res));
        that.setData({ total: res.total})
        if (res.code == 0) {
          that.setData({ carList: res.data })
        }
      }
    })
  },
  del: function (e) {
    let that = this;
    let id = e.currentTarget.id;
    console.log(id);
    wx.showModal({
      title: '提示',
      content: '确定删除此车辆吗？',
      success: function (res) {
        if (res.confirm) {
          let openId = wx.getStorageSync("openidKey");
          wx.showLoading({ title: '请稍等...', })
          wx.request({
            header: { "openId": openId},
            url: httpsUrl + "/car/del?aid="+id,
            dataType: "json",
            method: "DELETE",
            // data: { "aid": id },
            success: function (res) {
              wx.hideLoading();
              res = res.data;
              console.info(JSON.stringify(res));
              if (res.code == 0) {
                commonUtil.showSuccessToast("操作成功");
                that.list();
              } else {
                commonUtil.showErrorToast(res.message);
              }
            }
          })
        } else if (res.cancel) { }
      }
    })

  },
  //设置显示块id
  titleSelect: function (e) {
    let id = e.currentTarget.id;
    this.setData({
      titleFlag: id,
    })
    this.list();
  },
  carInfo:function(e){
    let id = e.currentTarget.id;
    wx.setStorageSync("aidKey", id);
    wx.navigateTo({
      url: '../carInfo/carInfo',
    })
  },
  photo:function(e){
    let id = e.currentTarget.id;
    wx.setStorageSync("aidKey", id);
    wx.navigateTo({
      url: '../photo/photo',
    })
  },
  monitor: function (e) {
    let id = e.currentTarget.id;
    wx.setStorageSync("aidKey", id);
    wx.navigateTo({
      url: '../monitor/monitor',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.list();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.list();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})